package com.xyz.controller;

import com.xyz.aop.Param;
import com.xyz.service.BaseService;
import com.xyz.util.dto.DataResult;
import com.xyz.util.dto.LoginInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("base")
public class BaseController {

    private static final Logger logger = LoggerFactory.getLogger(BaseController.class);

    @Autowired
    private BaseService baseService;

    @PostMapping("selectDictType")
    public DataResult selectDictType(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String name,
            @Param(isRequired = false) String code
    ) {
        try {
            return baseService.selectDictType(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), name, code);
        } catch (Exception e) {
            logger.error("selectDictType", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertDictType")
    public DataResult insertDictType(
            LoginInfo li,
            @Param String name,
            @Param String code,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort,
            @Param(isRequired = false) String remark
    ) {
        try {
            return baseService.insertDictType(li, name, code, sort, remark);
        } catch (Exception e) {
            logger.error("insertDictType", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updateDictType")
    public DataResult updateDictType(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String name,
            @Param String code,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort,
            @Param(isRequired = false) String remark
    ) {
        try {
            return baseService.updateDictType(li, Long.parseLong(id), name, code, sort, remark);
        } catch (Exception e) {
            logger.error("updateDictType", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deleteDictType")
    public DataResult deleteDictType(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return baseService.deleteDictType(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deleteDictType", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectDictData")
    public DataResult selectDictData(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return baseService.selectDictData(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), Long.parseLong(id));
        } catch (Exception e) {
            logger.error("selectDictData", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertDictData")
    public DataResult insertDictData(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String name,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String value,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort,
            @Param(isRequired = false) String color,
            @Param(isRequired = false) String remark
    ) {
        try {
            return baseService.insertDictData(li, Long.parseLong(id), name, Integer.parseInt(value), sort, color, remark);
        } catch (Exception e) {
            logger.error("insertDictData", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updateDictData")
    public DataResult updateDictData(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String name,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String value,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort,
            @Param(isRequired = false) String color,
            @Param(isRequired = false) String remark
    ) {
        try {
            return baseService.updateDictData(li, Long.parseLong(id), name, Integer.parseInt(value), sort, color, remark);
        } catch (Exception e) {
            logger.error("updateDictData", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deleteDictData")
    public DataResult deleteDictData(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return baseService.deleteDictData(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deleteDictData", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertArea")
    public DataResult insertArea(
            LoginInfo li,
            @Param String name,
            @Param String code,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort
    ) {
        try {
            return baseService.insertArea(li, name, code, sort);
        } catch (Exception e) {
            logger.error("insertArea", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updateArea")
    public DataResult updateArea(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String name,
            @Param String code,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort
    ) {
        try {
            return baseService.updateArea(li, Long.parseLong(id), name, code, sort);
        } catch (Exception e) {
            logger.error("updateArea", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deleteArea")
    public DataResult deleteArea(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return baseService.deleteArea(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deleteArea", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertSystem")
    public DataResult insertSystem(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String areaTreeId,
            @Param String name,
            @Param String code,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort
    ) {
        try {
            return baseService.insertSystem(li, Long.parseLong(areaTreeId), name, code, sort);
        } catch (Exception e) {
            logger.error("insertSystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updateSystem")
    public DataResult updateSystem(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String areaTreeId,
            @Param String name,
            @Param String code,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort
    ) {
        try {
            return baseService.updateSystem(li, Long.parseLong(id), Long.parseLong(areaTreeId), name, code, sort);
        } catch (Exception e) {
            logger.error("updateSystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deleteSystem")
    public DataResult deleteSystem(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return baseService.deleteSystem(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deleteSystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertSubsystem")
    public DataResult insertSubsystem(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String systemTreeId,
            @Param String name,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String emType,
            @Param String code,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort
    ) {
        try {
            return baseService.insertSubsystem(li, Long.parseLong(systemTreeId), name, Integer.parseInt(emType), code, sort);
            //return baseService.insertSubsystem(li, Long.parseLong(systemTreeId), name, 99, code, sort);
        } catch (Exception e) {
            logger.error("insertSubsystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updateSubsystem")
    public DataResult updateSubsystem(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String systemTreeId,
            @Param String name,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String emType,
            @Param String code,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String sort
    ) {
        try {
            return baseService.updateSubsystem(li, Long.parseLong(id), Long.parseLong(systemTreeId), name, Integer.parseInt(emType), code, sort);
        } catch (Exception e) {
            logger.error("updateSubsystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deleteSubsystem")
    public DataResult deleteSubsystem(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return baseService.deleteSubsystem(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deleteSubsystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPatrolEm")
    public DataResult selectPatrolEm(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String name
    ) {
        try {
            return baseService.selectPatrolEm(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), name);
        } catch (Exception e) {
            logger.error("selectPatrolEm", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPatrolSubsystem")
    public DataResult selectPatrolSubsystem(
            LoginInfo li,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String subsystemTreeId,
            @Param(isRequired = false) String name
    ) {
        try {
            return baseService.selectPatrolSubsystem(li, pageNum, pageSize, subsystemTreeId, name);
        } catch (Exception e) {
            logger.error("selectPatrolSubsystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPatrolSubsystem")
    public DataResult insertPatrolSubsystem(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String subsystemTreeId,
            @Param String name
    ) {
        try {
            return baseService.insertPatrolSubsystem(
                    li, Long.parseLong(subsystemTreeId), name
            );
        } catch (Exception e) {
            logger.error("insertPatrolSubsystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePatrolSubsystem")
    public DataResult updatePatrolSubsystem(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String subsystemTreeId,
            @Param String name
    ) {
        try {
            return baseService.updatePatrolSubsystem(
                    li, Long.parseLong(id), Long.parseLong(subsystemTreeId), name
            );
        } catch (Exception e) {
            logger.error("updatePatrolSubsystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deletePatrolSubsystem")
    public DataResult deletePatrolSubsystem(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return baseService.deletePatrolSubsystem(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deletePatrolSubsystem", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPatrolFixed")
    public DataResult selectPatrolFixed(
            LoginInfo li,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String name
    ) {
        try {
            return baseService.selectPatrolFixed(li, pageNum, pageSize, name);
        } catch (Exception e) {
            logger.error("selectPatrolFixed", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPatrolFixed")
    public DataResult insertPatrolFixed(
            LoginInfo li,
            @Param String name
    ) {
        try {
            return baseService.insertPatrolFixed(
                    li, name
            );
        } catch (Exception e) {
            logger.error("insertPatrolFixed", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePatrolFixed")
    public DataResult updatePatrolFixed(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param String name
    ) {
        try {
            return baseService.updatePatrolFixed(
                    li, Long.parseLong(id), name
            );
        } catch (Exception e) {
            logger.error("updatePatrolFixed", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deletePatrolFixed")
    public DataResult deletePatrolFixed(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return baseService.deletePatrolFixed(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deletePatrolFixed", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectPatrolTask")
    public DataResult selectPatrolTask(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String type,
            @Param(isRequired = false) String typeId
    ) {
        try {
            return baseService.selectPatrolTask(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), Integer.parseInt(type), typeId);
        } catch (Exception e) {
            logger.error("selectPatrolTask", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("insertPatrolTask")
    public DataResult insertPatrolTask(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String type,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String typeId,
            @Param String project,
            @Param String way,
            @Param String standard,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String isRecorded,
            @Param(isRequired = false) String sort,
            @Param(isRequired = false) String childType
    ) {
        try {
            return baseService.insertPatrolTask(
                    li, Integer.parseInt(type), Integer.parseInt(typeId),
                    project, way, standard, Integer.parseInt(isRecorded), sort, childType
            );
        } catch (Exception e) {
            logger.error("insertPatrolTask", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updatePatrolTask")
    public DataResult updatePatrolTask(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String type,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String typeId,
            @Param String project,
            @Param String way,
            @Param String standard,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String isRecorded,
            @Param(isRequired = false) String sort,
            @Param(isRequired = false) String childType
    ) {
        try {
            return baseService.updatePatrolTask(
                    li, Long.parseLong(id), Integer.parseInt(type), Integer.parseInt(typeId),
                    project, way, standard, Integer.parseInt(isRecorded), sort, childType
            );
        } catch (Exception e) {
            logger.error("updatePatrolTask", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("deletePatrolTask")
    public DataResult deletePatrolTask(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String id
    ) {
        try {
            return baseService.deletePatrolTask(li, Long.parseLong(id));
        } catch (Exception e) {
            logger.error("deletePatrolTask", e);
            return DataResult.build9500();
        }
    }


}
